import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// @description:
/// @author
/// @date: 2024-08-13 10:36:36
class UnKnownPage extends StatelessWidget {
  const UnKnownPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BrnAppBar(title: '错误'),
      body: const Center(
        child: PlaceholderWidget(
          type: PlaceholderType.system,
          show: true,
          child: SizedBox(),
        ),
      ),
    );
  }
}

/// description
typedef OnNetStateCall = void Function(PlaceholderType state);

enum PlaceholderType {
  nomal,
  empty,
  system,
  network,
}

class PlaceholderWidget extends StatelessWidget {
  const PlaceholderWidget({
    super.key,
    this.type = PlaceholderType.nomal,
    required this.child,
    this.message,
    this.show = false,
  });
  final PlaceholderType type;
  final bool show;
  final Widget child;
  final String? message;

  @override
  Widget build(BuildContext context) {
    Widget image = Image.asset('assets/images/empty/data_empty.png', width: 200, height: 120, fit: BoxFit.contain);
    String content = '';
    if (type == PlaceholderType.empty) {
      image = Image.asset('assets/images/empty/system_error.png', width: 200, height: 120, fit: BoxFit.contain);
      content = '没有找到相关内容~'.tr;
    } else if (type == PlaceholderType.system) {
      image = Image.asset('assets/images/empty/data_empty.png', width: 200, height: 120, fit: BoxFit.contain);
      content = '系统错误，请稍后再试~'.tr;
    } else if (type == PlaceholderType.network) {
      image = Image.asset('assets/images/empty/network_error.png', width: 200, height: 120, fit: BoxFit.contain);
      content = '网咯错误，请稍检查网络~'.tr;
    }

    return show
        ? Container(
            width: double.infinity,
            height: double.infinity,
            alignment: Alignment.center,
            padding: const EdgeInsets.only(bottom: 10),
            child: Column(
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                image,
                const SizedBox(height: 30),
                Text(message ?? content, style: const TextStyle(fontSize: 14, color: Color(0xFF263B38))),
              ],
            ),
          )
        : child;
  }
}
